package com.dondedesigns.eh.controller.bullets;

import java.util.List;
import java.util.Set;

import com.dondedesigns.eh.controller.index.UserAware;
import com.dondedesigns.eh.persistence.BlUser;
import com.dondedesigns.eh.persistence.Bullet;
import com.dondedesigns.eh.persistence.User;
import com.dondedesigns.eh.persistence.dao.BlUserDAO;
import com.opensymphony.xwork2.ActionSupport;

public class UpdateBullets extends ActionSupport implements UserAware{
	
	private User user;
	private BlUser blUser;
	private String blGun;
	private String blBullets;
	private String blUserId;
	
	private BlUserDAO blUserDAO;

	@Override
	public String execute() throws Exception {
		blUser = blUserDAO.find(Long.parseLong(blUserId));
		Bullet bullet = new Bullet ();
		bullet.setGun(blGun);
		bullet.setAmount(Integer.parseInt(blBullets));
		blUser.addBullets (bullet);
		blUser.setLastBulletUpdate (bullet.getUpdateDate());
		blUserDAO.update(blUser);
		return SUCCESS;
	}

	@Override
	public void setUser(User user) {
		this.user = user;
	}
	
	public void setBlUser(BlUser blUser) {
		this.blUser = blUser;
	}

	public String getBlGun() {
		return blGun;
	}

	public void setBlGun(String blGun) {
		this.blGun = blGun;
	}

	public String getBlBullets() {
		return blBullets;
	}

	public void setBlBullets(String blBullets) {
		this.blBullets = blBullets;
	}
	
	public void setBlUserDAO(BlUserDAO blUserDAO) {
		this.blUserDAO = blUserDAO;
	}

	public void setBlUserId(String blUserId) {
		this.blUserId = blUserId;
	}
	
	public Set<BlUser> getBlUsersList() {
		return user.getBlUsers();

	}
}
